﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<script src="~/lib/layui/layui.js"></script>
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />

<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.21-rc/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form" action="">
        <div>
            <div class="layui-inline">
                <label class="layui-form-label">转移单编号</label>
                <div class="layui-input-block">
                    <input type="text" name="username" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" style="width:200px" id="transferOrderNumber">
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-form" onclick="Automatic()">
                    <input type="checkbox" name="CCC" title="自动生成|关闭自动生成" lay-skin="switch" class="GMon" value="1">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">转移单名称</label>
                <div class="layui-input-block">
                    <input type="text" name="username" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" style="width:200px" id="transferOrderName">
                </div>
            </div>
        </div>
        <br />
        <br />
        <div class="layui-form-item">
            <label class="layui-form-label">转移单类型</label>
            <div class="layui-input-block">
                <input type="radio" name="kl" class="sex" value="0" title="内部转移">
                <input type="radio" name="kl" class="sex" value="1" title="外部转移">
            </div>
        </div>
        <br />
        <br />
        <div>
            <div class="layui-inline">
                <label class="layui-form-label">移除仓库</label>
                <div class="layui-input-inline">
                    <div class="layui-form layui-row layui-col-space16">
                        <div class="layui-col-md6" id="StashId">
                            <select id="city">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">移入仓库</label>
                <div class="layui-input-inline">
                    <div class="layui-form layui-row layui-col-space16">
                        <div class="layui-col-md6" id="StashIds">
                            <select id="gh">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">移库日期</label>
                <div class="layui-input-block">
                    <input type="date" name="username" lay-verify="required" autocomplete="off" class="layui-input" id="transfertime">
                </div>
            </div>
        </div>
        <br />
        <br />
        <div>
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="" placeholder="多行文本框" class="layui-textarea" style="width:500px" id="infoMess"></textarea>
            </div>
        </div>
        <div class="layui-btn-container">
            <button type="button" class="layui-btn " onclick="TransferAdd()">新增</button>
        </div>
    </form>

    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.21-rc/dist/layui.js"></script>
    <script>

        $(()=>{


            Stash()
        })

        //仓库显示
        function Stash() {

            var stashNum = "";
            var stashName = "";

            $.ajax({

                url: '@ViewBag.FoundationRead'+'/api/Acquire/StashHtml',
                data: JSON.stringify({ stashNum: stashNum, stashName: stashName }),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: function (res) {
                    $(res.data).each(function (i, item) {
                        $('#city').append(`<option value="` + item.stashId + `">` + item.stashName + `</option>`);
                    })
                    $(res.data).each(function (i, item) {
                        $('#gh').append(`<option value="` + item.stashId + `">` + item.stashName + `</option>`);
                    })
                    layui.form.render("select");
                }
            })
        }

        //自动生成
        function Automatic() {


            var gh = $('.GMon:checked').val()
            console.log(gh);

            if (gh == 1) {
                var Encoding = "MG" + Math.random().toString().substring(2, 6);

                $("#transferOrderNumber").val(Encoding)
            }
            if (gh != 1) {
                $("#transferOrderNumber").val('');
            }
        }



        //转移挑拨单新增
        function TransferAdd() {
            var date = {
                TransferOrderNumber: $("#transferOrderNumber").val(),
                TransferOrderName: $("#transferOrderName").val(),
                IsType: $(".sex:checked").val(),
                StashId: $("#city").val(),
                StashIds: $("#gh").val(),
                infoMess: $("#infoMess").val(),
                Transfertime: $("#transfertime").val(),
            };
            console.log(date);
            $.ajax({

                url:'@ViewBag.FoundationWrite' +'/api/Jocker/TransferCreate',
                data: JSON.stringify(date),
                type: "post",
                async: false,
                dataType: "json",
                contentType: "application/json",
                success: function (res) {

                    console.log(res.code,'zzzz')
                   if(res.code>0)
                   {
                       alert("添加成功");
                       layer.close(layer.index); //它获取的始终是最新弹出的某个层，值是由layer内部动态递增计算的
                       var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                       parent.layer.close(index); //再执行关闭
                   }
                }
            })
        }
    </script>

</body>
</html>